package com.tsingeye.viid.task;

import com.tsingeye.viid.mapper.ViidFaceImageMapper;
import com.tsingeye.viid.mapper.ViidFaceMapper;
import com.tsingeye.viid.mapper.ViidMotorVehicleImageMapper;
import com.tsingeye.viid.mapper.ViidMotorVehicleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;

@Component("viidTask")
public class ViidTask {

    @Autowired
    private ViidFaceMapper viidFaceMapper;

    @Autowired
    private ViidFaceImageMapper viidFaceImageMapper;

    @Autowired
    private ViidMotorVehicleMapper viidMotorVehicleMapper;

    @Autowired
    private ViidMotorVehicleImageMapper viidMotorVehicleImageMapper;


    public void deleteExpireData(Integer expireDay) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH) - expireDay,0,0,0);
        long expireTimestamp = calendar.getTimeInMillis() / 1000;

        viidFaceMapper.deleteViidFaceByDate(expireTimestamp);
        viidFaceImageMapper.deleteViidFaceImageByDate(expireTimestamp);
        viidMotorVehicleMapper.deleteViidMotorVehicleByDate(expireTimestamp);
        viidMotorVehicleImageMapper.deleteViidMotorVehicleImageByDate(expireTimestamp);
    }
}
